package mortal.game.control
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import modules.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class SpeakerController extends Controller
    {

        public function SpeakerController()
        {
            
        }

        override protected function initView() : IView
        {
            var _loc_1:* = new SpeakerModule();
            _loc_1.addEventListener(EventName.ChatShowSpeaker, this.onShowSpeakerHandler);
            return _loc_1;
        }

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.ChatShowSpeaker, this.onShowSpeakerHandler);
            Dispatcher.addEventListener(EventName.ChatSpeakerSend, this.onSendSpeakerMsgHandler);
            NetDispatcher.addCmdListener(ServerCommand.ChatMessageUpdate, this.onChatMessageUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.serverBagDataChangehandler);
            
        }

        private function onShowSpeakerHandler(event:DataEvent) : void
        {
            (view as SpeakerModule).resetSpeakTxt();
            GameManager.instance.popupWindow(ModuleType.Speaker);
            if (!view.isHide)
            {
                (view as SpeakerModule).checkSpreakNum();
                (view as SpeakerModule).updateSpeakerNum();
            }
            
        }

        private function onSendSpeakerMsgHandler(event:DataEvent) : void
        {
            var _loc_2:* = EChatType._EChatTypeTrumpet;
            var _loc_3:* = event.data as String;
            var _loc_4:* = (view as SpeakerModule).textColor;
            GameProxy.chatProxy.SendMessage(_loc_2, _loc_3, _loc_4);
            
        }

        private function onChatMessageUpdateHandler(param1:Object) : void
        {
            var _loc_9:String = null;
            var _loc_2:* = param1 as SChatMsg;
            var _loc_3:* = _loc_2.chatType;
            var _loc_4:* = _loc_2.fromPlayer.name;
            var _loc_5:* = _loc_2.content;
            _loc_5 = FilterText.instance.getFilterStr("：" + _loc_5);
            var _loc_6:* = new Array(16763904, 268435200, 65280, 255, 16711935);
            var _loc_7:* = new Array(16763904, 268435200, 65280, 255, 16711935);
            var _loc_8:* = new Array(16763904, 268435200, 65280, 255, 16711935).indexOf(_loc_2.font);
            if (new Array(16763904, 268435200, 65280, 255, 16711935).indexOf(_loc_2.font) != -1)
            {
                _loc_9 = _loc_6[_loc_8];
            }
            else
            {
                _loc_9 = "0xFF0000";
            }
            var _loc_10:* = new MsgTypeImpl(null, _loc_9, 15000);
            var _loc_11:* = new PlayerMiniInfo(_loc_2.fromPlayer);
            if (_loc_3 == EChatType._EChatTypeTrumpet)
            {
                if (cache.role.playerInfo.name == _loc_4)
                {
                    MsgManager.addBroadCast("发送成功");
                }
                MsgManager.addSpeakerText(_loc_11, _loc_5, _loc_10);
            }
            
        }

        private function serverBagDataChangehandler(param1:Object) : void
        {
            (view as SpeakerModule).updateSpeakerNum();
            
        }

    }
}
